//
//  RecommendViewController.m
//  Ai
//
//  Created by 杜超男 on 2019/3/11.
//  Copyright © 2019年 杜超男. All rights reserved.
//

#import "RecommendViewController.h"
#import "Masonry.h"
@interface RecommendViewController ()<UICollectionViewDelegate , UICollectionViewDataSource>

@end
static NSString *reuseCell = @"123";
@implementation RecommendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    //创建流水布局
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    //格子的大小
    layout.itemSize = CGSizeMake(100, 100);
    //行间距
    layout.minimumLineSpacing = 15;
    //列间距
    layout.minimumInteritemSpacing = 15;
    //分区间距
    layout.sectionInset = UIEdgeInsetsMake(15, 30, 30, 15);
    //
    
    //网格视图 (表格 -> 需要注册,需要创建布局)
    //1.frame
    UICollectionView *clV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 300) collectionViewLayout:layout];
    //2.数据源和代理
    clV.delegate = self;
    clV.dataSource = self;
    clV.backgroundColor = [UIColor whiteColor];
    //3.添加到主视图
    [self.view addSubview:clV];
    [clV mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom).inset(0);
    }];
    //注册网格cell
    [clV registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseCell];
    
    // Do any additional setup after loading the view.
}
//分区个数 (几组)
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
//每个分区有几个item (小格子的个数)
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 10;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    //创建重用标识符
    
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseCell forIndexPath:indexPath];
    //设置格子的背景颜色
    cell.backgroundColor = [UIColor redColor];
    //初始化图片框
    UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
    //添加图片
//    imgV.image = [UIImage imageNamed:arrimG[indexPath.row]];
    //添加到网格里面
    [cell addSubview:imgV];
    //设置文字
    UILabel *lb1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 80, 80, 20)];
    //设置文字
//    lb1.text = arrimG[indexPath.row];
    //文字居中
    lb1.textAlignment = NSTextAlignmentCenter;
    //添加到网格里面
    [cell addSubview:lb1];
    return cell;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
